<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学院管理</title>

    <%@ include file="base.jsp"%>

    <link rel="stylesheet" href="css/x-admin.css" media="all"/>
    <script src="lib/layui/layui.js" charset="utf-8"></script>
    <script src="js/x-layui.js" charset="utf-8"></script>
    <script src="js/jquery-3.6.0.js"></script>
    <script>

        //前端校验
        //onsubmit 事件是提交时触发，如果事件触发的函数返回false，表单不提交，如果返回true，表单提交
        function checkForm() {
            var academyName = document.getElementById("academyName").value;
            var intro = document.getElementById("intro").value;
            var cphone = document.getElementById("cphone").value;

            var flag = true;

            if (null == intro || intro == '') {
                alert("请输入学院地址");
                return false;
            }
            if (null == cphone || cphone == '') {
                alert("请输入学院联系方式");
                return false;
            }
            if (null == academyName || academyName == '') {
                alert("请输入学院名称");
                return false;
            } else {
                $.ajax({
                    url: '<%=request.getContextPath()%>/admin/collegeController',
                    data: {
                        "fun": "exit",
                        "cname": academyName
                    },
                    async: false,
                    dataType: 'json',
                    success(data) {
                        console.log(data.code)

                        if (data.code == 0 || data.code == "0") {
                            $("#msg").text(data.msg)
                            flag = false;
                        }
                    }
                })
                if (flag === false){
                    return false;
                }else {
                    x_admin_close();
                    return true;
                }
            }
        }
    </script>
</head>

<body>
<div class="x-body">
    <form action="admin/collegeController" method="post" target="_parent" onsubmit="return checkForm()">
        <input type="hidden" name="fun" value="add"/>
        <input type="hidden" name="total" value="${param.total}"/>
        <input type="hidden" name="pages" value="${param.pages}"/>

        <div class="layui-form-item">
            <div style="color: red" id="msg">${msg}</div>
            <label for="academyName" class="layui-form-label"> <span class="x-red">*</span>学院名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="academyName" name="cname" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>必填
            </div>
        </div>

        <div class="layui-form-item">
            <label for="intro" class="layui-form-label"> <span class="x-red">*</span>学院地址
            </label>
            <div class="layui-input-inline">
                <input type="text" id="intro" name="caddress" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>必填
            </div>
        </div>
        <div class="layui-form-item">
            <label for="cphone" class="layui-form-label"> <span class="x-red">*</span>联系方式
            </label>
            <div class="layui-input-inline">
                <input type="text" id="cphone" name="cphone" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>必填
            </div>
        </div>

        <div class="layui-form-item">
            <label for="" class="layui-form-label"></label>
            <button type="submit" class="layui-btn">添加</button>
        </div>
    </form>
</div>
</body>

</html>